package com.hnkywl.sts.service.report;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.report.CwkcDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-15
 * Time: 下午9:23
 * To change this template use File | Settings | File Templates.
 */
@Service
public class CwkcService {
    private CwkcDao cwkcDao;

    /**
     * 财务库存报表
     *
     * @param gsid
     * @param endDate
     * @param pageNo
     * @param pageSize
     * @return
     */
    public String cwkcList(Long gsid, Date endDate,String wzbm,Integer wzdl, Integer pageNo, Integer pageSize) {
        Map<String, Object> result = cwkcDao.cwkcList(gsid, endDate,wzbm,wzdl, pageNo, pageSize);
        Integer total=(Integer)result.get("total");
        List<Map> rows = (List<Map>)result.get("rows");
        List<Map> footer = (List<Map>)result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson +",\"total\":"+total+ "}";
        return json;
    }

    public Map cwkcListExport(Long gsid, Date endDate,String wzbm,Integer wzdl){
        Map<String, Object> result = cwkcDao.cwkcList(gsid, endDate,wzbm,wzdl, 1, 1000000);
        return result;
    }

    @Autowired
    public void setCwkcDao(CwkcDao cwkcDao) {
        this.cwkcDao = cwkcDao;
    }
}
